package com.mofeng.myshop.controller.portal;


import com.mofeng.myshop.domain.dto.search.CommoditySearchDto;
import com.mofeng.myshop.service.ICommodityService;
import com.mofeng.myshop.until.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author MoFeng
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/portal/commodity")
@RequiredArgsConstructor
@Tag(name = "商品的接口", description = "类介绍")
public class CommodityController {
    private final ICommodityService commodityService;

    @Operation(summary = "获取商品列表")
    @GetMapping("/list/{page}/{size}")
    public R getCommodityByPage(@PathVariable("page") int page,
                                @PathVariable("size") int size,
                                @RequestParam(value = "categoryId", required = false) String categoryId,
                                @RequestParam(value = "projectId", required = false) String projectId,
                                @RequestParam(value = "name", required = false) String name) {
        CommoditySearchDto commoditySearch = new CommoditySearchDto();
        commoditySearch.setPage(page);
        commoditySearch.setSize(size);
        commoditySearch.setKeyword(name);
        commoditySearch.setCommodityCategoryId(categoryId);
        commoditySearch.setProjectId(projectId);
        return commodityService.getCommodityByPagePortal(commoditySearch);
    }
}
